<!DOCTYPE html>

<head>
    <title>参与抽奖</title>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.1/weui.min.css" />
	<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
	<style type="text/css">
		#wechat-web-container{position: relative;}
		#wechat-web-container .bg{width: 100%;border: 0;vertical-align: middle;}
		#wechat-web-container .btn_box{display: flex; align-items: flex-end;justify-content: center;position: absolute;width: 100%;height: 100%;left: 0;top: 0;z-index: 99;text-align: center;}
	</style>
</head>
<body>
<div id="wechat-web-container">
	<img class="bg" src="./img/bg2.jpg" />
	<div class="btn_box">
		<div style="padding-bottom: 30px;">
			<wx-open-launch-weapp id="launch-btn" username="gh_205c1dc88518" path="packageB/activity/activityAlliance/activityAlliance?id=3539965176&sc=2246756995">
				<template>
		            <style>
						#toWxapp{border: 0;width: 80%;overflow: hidden;background: none;margin-left: -10px;}
						#toWxapp .btn{width: 100%;border: 0;vertical-align: middle;}
						#toWxapp:active{opacity: .8;}
					</style>
					<button id="toWxapp">
						<img class="btn" src="http://newsales.chinaesf.net/yl/pages/html/img/btn.png" />
					</button>
				</template>
			</wx-open-launch-weapp>
		</div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$.ajax({
		url: 'http://newsales.chinaesf.net/yl/wechat/getJSSdk',
		success: function(res){
			console.log("getJSSdk=", res);
			if (res.code === 1000) {
				var config = res.data;
				wx.config({
					debug: false,
					appId: config.appId,
					timestamp: config.timestamp,
					nonceStr: config.nonceStr,
					signature: config.signature,
					jsApiList: ['chooseImage', 'previewImage'],
					openTagList:['wx-open-launch-weapp']
				});
				wx.ready(function () {
					var btn = document.getElementById('launch-btn');
					btn.addEventListener('launch', function (e) {
						console.log('success');
						// alert('success')
						toWxapp();
					});
					btn.addEventListener('error', function (e) {
						console.log('fail', e.detail);
						alert('fail='+e.detail);
						// alert('fail', e.detail)
					});
				});
			} else {
				alert("请求失败，请稍后再试！");
			}
		},
		error: function (err) {
			alert("网络繁忙，请稍后再试！");
		}
	})
});
function toWxapp(){
    console.log("跳转到指定小程序");
	document.getElementById("toWxapp").onclick();
};
</script>
</body>
</html>